package com.dst.dao.impl;

import com.dst.dao.UserDao;
import com.dst.eneity.User;
import com.dst.util.JdbcUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class UserDaoImpl implements UserDao {
    @Override
    public User selectUserByUsernameandPassword(String username, String password) {
        Connection conn=null;
        PreparedStatement pstmt=null;
        ResultSet rs=null;
        User user=null;
        try {
            conn = JdbcUtils.getConnection();
            String sql="select * from t_user where username=? and password=?";
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1,username);
            pstmt.setString(2,password);
            rs = pstmt.executeQuery();
            while(rs.next()){
                int id = rs.getInt("id");
                String username1 = rs.getString("username");
                String password1 = rs.getString("password");
                user = new User(id,username1,password1);
        }
    } catch (Exception e) {
            e.printStackTrace();
        }
        return user;
    }
}
